<!--
  #%L
  thinkbig-ui-feed-manager
  %%
  Copyright (C) 2017 ThinkBig Analytics
  %%
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  #L%
  -->
<vertical-section-layout section-title="Category Definition" on-delete="vm.onDelete()" allow-delete="vm.canDelete()" is-delete-visible="vm.model.id != null" on-save-edit="vm.onSave()"
                         on-edit="vm.onEdit()" on-cancel-edit="vm.onCancel()" editable="vm.isEditable" allow-edit="vm.allowEdit" the-form="vm.categoryForm" is-valid="vm.isValid">
  <readonly-section>
    <div layout="row" class="layout-padding-top-bottom" flex>
      <span flex="25" class="property-name">Category Name</span>

      <div flex="25"> {{vm.model.name}}</div>
      <span flex="5"></span>
      <span flex="25" class="property-name">System Name</span>

      <div flex>{{vm.model.systemName}}</div>
    </div>
    <div layout="row" class="layout-padding-top-bottom">
      <span flex="25" class="property-name">Description</span>

      <div flex>
        {{vm.model.description}}
      </div>
    </div>
    <div layout="row" class="layout-padding-top-bottom" ng-if="vm.securityGroupsEnabled == true">
      <span flex="25" class="property-name">Hadoop Security Groups</span>

      <div flex>
        {{vm.splitSecurityGroups()}}
      </div>
    </div>
    <div layout="row" class="layout-padding-top-bottom" layout-align="start start">
      <span flex="25" class="property-name">Icon</span>

      <div layout="column">
        <ng-md-icon icon="{{vm.model.icon}}" ng-style="vm.getIconColorStyle(vm.model.iconColor)" style="margin:inherit" size="45"></ng-md-icon>
      </div>
    </div>
  </readonly-section>
  <editable-section>
    <ng-form name="vm.categoryForm">
      <div layout="row" flex="100">
        <md-input-container class="md-block" flex="40">
          <label>Name</label>
          <input name="categoryName" ng-model="vm.editModel.name" required/>

          <div ng-messages="vm.categoryForm.categoryName.$error" md-auto-hide="false">
            <div ng-message="required">A category name is required.</div>
            <div ng-message="duplicateDisplayName">There is an existing category with that name.</div>
            <div ng-message="reservedCategoryName">That category is reserved. Please choose another category.</div>
          </div>
        </md-input-container>
        <div flex="10"></div>
        <md-input-container flex="40">
          <label>System Name</label>

          <input id="systemName" name="systemName" ng-readonly="!vm.isSystemNameEditable() || vm.hasFeeds()" ng-model="vm.editModel.systemName" required/>

          <div class="hint">
            <span>{{vm.getSystemNameDescription()}}</span>
            <br>
            <a href="" ng-if="!vm.isSystemNameEditable() && vm.hasNoFeeds()" ng-click="vm.allowEditSystemName()">Let me change system name</a>
          </div>
          <div ng-messages="vm.categoryForm.systemName.$error" md-auto-hide="false">
            <div ng-message="required">A category system name is required.</div>
            <div ng-message="invalidName">Invalid, must not contain other than alpha-numeric and underscores.</div>
            <div ng-message="duplicateSystemName">There is an existing category with that system name.</div>
            <div ng-message="reservedCategoryName">That category is reserved. Please choose another category.</div>
          </div>
        </md-input-container>

      </div>

      <md-input-container class="md-block">
        <label>Description</label>
        <textarea ng-model="vm.editModel.description"></textarea>
      </md-input-container>

      <md-input-container class="md-block layout-padding-top-bottom flex-gt-sm condensed" flex-gt-sm="" style="" ng-if="vm.securityGroupsEnabled == true">
        <label class="label-small md-container-ignore">Hadoop Security Groups</label>
        <md-chips ng-model="vm.editModel.securityGroups" md-autocomplete-snap
                  md-transform-chip="vm.transformChip($chip)"
                  md-require-match="true" class="layout-padding-top-bottom">
          <md-autocomplete
              md-min-length="0"
              md-selected-item="vm.securityGroupChips.selectedItem"
              md-search-text="vm.securityGroupChips.searchText"
              md-items="item in vm.categorySecurityGroups.querySearch(vm.securityGroupChips.searchText)"
              md-item-text="item.name"
              md-no-cache="true"
              placeholder="Add a Hadoop Security Group">
            <span md-highlight-text="vm.securityGroupChips.searchText">{{item.name}}</span>
          </md-autocomplete>
          <md-chip-template>
                            <span>
                              <strong>{{$chip.name}}</strong>
                            </span>
          </md-chip-template>
        </md-chips>
      </md-input-container>

      <div layout="column">
        <div layout="row" layout-align="start start" class="layout-padding-top-bottom">
          <span class="md-input-label" style="font-size: 11px;" flex="25">Icon </span>
          <ng-md-icon icon="{{vm.editModel.icon}}" size="45" style="margin:inherit;" ng-style="vm.getIconColorStyle(vm.editModel.iconColor)"></ng-md-icon>
          <md-button class="md-primary" ng-click="vm.showIconPicker()" style="margin-left:35px;">Change Icon</md-button>
        </div>
      </div>

      <thinkbig-property-list-editor properties="vm.editModel.userProperties" is-valid="vm.isValid" ng-if="vm.model.id == null"></thinkbig-property-list-editor>
    </ng-form>
  </editable-section>
</vertical-section-layout>

